package com.getmoney;

/**
 * Version: 1.1
 * Author: TangJun
 * Date: 2024-07-27
 */
public class Bank extends Thread{
    private static int money = 10000;

    @Override
    public void run() {
        while (money > 0) {
            getMoney();
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println("银行里没钱了");
    }

    public void getMoney() {
        synchronized(this) {
            money -= 1000;
            System.out.println(Thread.currentThread().getName() + "取钱1000块"
                                + "，当前剩余：" + money);
        }
    }
}
